package com.example.administrator.appli.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

import com.example.administrator.appli.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2017/5/9.
 */
public class HandlerDialog extends Dialog {
    Handler mHandler;
    String TAG="HandlerDialog";

    public HandlerDialog(Context context, Handler handler) {
        super(context);
        this.mHandler = handler;
    }

    public HandlerDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected HandlerDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    TextView tv_dialog;
    Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_handler);
        tv_dialog = (TextView) findViewById(R.id.tv_dialoig);

        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                mHandler.sendEmptyMessage(101);
            }
        }, 2000, 2000);

    }

    @Override
    protected void onStop() {
        super.onStop();
        if (timer != null)
            timer.cancel();
        Log.e(TAG, "onStop: " );

    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (timer != null)
            timer.cancel();
        Log.e(TAG, "onDetachedFromWindow: " );
    }

    @Override
    public void dismiss() {
        super.dismiss();
        Log.e(TAG, "dismiss: ");
        if (timer != null)
            timer.cancel();
    }
}
